<?php 
// ถ้าเป็น ITS USer จึงจะ save และ ลบ locations ได้
$user_prefix = $session->read('Auth.User.prefix');
$from_its_user = $session->read('Auth.User.Extend.from_its_user');
?>
<table class="data">
    <thead>
        <tr>
            <th width="20px"><?php echo 'No'; ?></th>
            <th><?php echo 'Name'; ?></th>
            <?php if ($user_prefix == ITS_PREFIX || $from_its_user == true) : ?>
            <th class="action">&nbsp;</th>
            <?php endif; ?>
        </tr>
    </thead>
    <tbody>
        <?php if (empty($this->data)) : // ถ้าไม่มีข้อมูล ?>
        <tr>
            <td colspan="3"><div class="caption" style="font-size: 100%">This customer product doesn't has any specific locations. All locations can be used for stock in.</div></td>
        </tr>
        <? else : // ถ้ามีข้อมูล ?>
            <?php $i = 0; foreach($this->data as $cpsLocation): ?>
                <?php
                $tableCell = array();
                $tableCell[] = ++$i;
                $tableCell[] = $html->tag('span', $cpsLocation['CustLocation']['name'], array('id' => "name$i"));
                if ($user_prefix == ITS_PREFIX || $from_its_user == true) {
                    $tableCell[] = $my->confirmLink($html->image('icon/delete.png', array('title' => 'delete', 'alt' => 'delete')), "its_cust_product_sites/delete_location/{$cpsLocation['CPSLocation']['id']}", 'Do you want to delete \"' . $cpsLocation['CustLocation']['name'] . '\"?', 'divCPSLocations', false);
                }
                echo $html->tableCells($tableCell, array('class' => 'odd-cell'), array('class' => 'even-cell'));
                ?>
            <?php endforeach; ?>
        <?php endif; ?>
        <?php if ($user_prefix == ITS_PREFIX || $from_its_user == true) : ?>
        <tr>
            <td>&nbsp;</td>
            <td colspan="2">
                    <?php echo $ajax->form(null, 'post', array('update' => 'divCPSLocations', 'indicator' => 'indicator', 'url' => array('controller' => 'its_cust_product_sites', 'action' => 'save_location'))); ?>
                    <?php echo $form->select('CPSLocation.cust_location_id', $custLocations); ?>
                    <?php echo $form->hidden('CPSLocation.cust_product_site_id', array('value' => $cust_product_site_id)); ?>
                <span class="toolbar" style="border: none; margin: 0px;">
                        <?php echo $this->element('toolbar', array('buttons' => array('save'))); ?>
                </span>
                    <?php echo $form->end(); ?>
            </td>
        </tr>
        <?php endif; ?>
    </tbody>
</table>
<?php //debug($this->data); ?>